package com.wyk.springbootdemo.entity;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class ExceptionController {

    @ExceptionHandler(value = Exception.class)
    public Object handleException(Exception e, HttpServletRequest request){
        Map map=new HashMap<String,Object>();
        map.put("code",100);
        map.put("msg",e.getMessage());
        map.put("url",request.getRequestURI());
        return map;
    }


    @ExceptionHandler(value = MyException.class)
    public Object MyException(MyException e, HttpServletRequest request){
        Map map=new HashMap<String,Object>();
        map.put("code",e.getCode());
        map.put("msg",e.getMsg());
        map.put("url",request.getRequestURI());
        return map;
    }
}
